package org.mapki;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;
    private int sizeX = 250;
    private int sizeY = 250;
    

    //private int[] mImageIds = new int[0];
    private Bitmap[] mImageBitmaps = new Bitmap[0];

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = c.obtainStyledAttributes(R.styleable.MainActivity);
        mGalleryItemBackground = a.getResourceId(
                R.styleable.MainActivity_android_galleryItemBackground, 0);
        a.recycle();
    }
    
    public void setImages(Bitmap[] bitmaps){
    	this.mImageBitmaps  = bitmaps;
    }
    public int getCount() {
//        return mImageIds.length;
        return mImageBitmaps.length;
    }
    
    public void setSize(int x, int y){
    	sizeX = x;
    	sizeY = y;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);

        i.setImageBitmap(mImageBitmaps[position]);
        i.setLayoutParams(new Gallery.LayoutParams(sizeX, sizeY));
        i.setScaleType(ImageView.ScaleType.FIT_CENTER);
        i.setBackgroundResource(mGalleryItemBackground);

        return i;
    }
}